package com.gem.mapper;

import com.gem.domain.CampusVisit;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: 玲
 * @Description: 我的院校拜访记录接口
 * @create 2019-10-16 16:07
 * @Modified By:
 */
@Mapper
public interface CampusVisitMapper {

    //保存拜访记录
    Integer save(CampusVisit campusVisit);

    //查询所有拜访记录
    @Select("select c.* ,u.personname from campus_visit c,user u where c.campus_gem_person = u.uid  and c.campus_visit_status > 0")
    List<CampusVisit> findAll();

    //根据id查拜访记录
    @Select("select c.* ,u.personname from campus_visit c,user u where c.campus_gem_person = u.uid and campus_visit_id = #{campusVisitId} and campus_visit_status > 0")
    CampusVisit findById(Integer campusVisitId);

    //根据id伪删除拜访记录
    @Update("update campus_visit set campus_visit_status = -1 where campus_visit_id = #{campusVisitId}")
    Integer deleteById(Integer campusVisitId);

    //更新拜访记录
    Integer update(CampusVisit campusVisit);

    //搜索拜访记录
    List<CampusVisit> search(CampusVisit campusVisit);

    //伪删除所选拜访记录
    Integer deleteAll(int[] campusVisitIds);

    //echarts
    //查询所有渠道专员id
    @Select("select distinct campus_gem_person from campus_visit where campus_visit_status > 0 ")
    List<Integer> findGemPersons();

    //计算每个渠道专员下负责的院校数
    @Select("select count(*) from campus_visit where campus_gem_person = #{gemPerson}  and campus_visit_status > 0")
    Integer findByGemPerson(@Param("gemPerson") Integer gemPerson);

    //查询所有院校名
    @Select("select distinct campus_name from campus_visit where campus_visit_status > 0")
    List<String> findCampus();

    //计算每个院校的拜访数
    @Select("select count(*) from campus_visit where campus_name = #{campus} and campus_visit_status > 0")
    Integer findByCampus(@Param("campus") String campus);

    //计算每个院校本周的拜访数
    @Select("select count(*) from campus_visit where campus_gem_person = #{gemPerson} and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(campus_visit_date) and campus_visit_status > 0")
    Integer findByGemPersonWeek(@Param("gemPerson") Integer gemPerson);

    //计算本周的总共拜访记录
    @Select("select count(*) from campus_visit where campus_name = #{campus} and  DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(campus_visit_date) and campus_visit_status > 0")
    Integer findByCampusWeek(@Param("campus") String campus);
}
